// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.regex.Matcher;
import se.krka.kahlua.vm.KahluaTable;
import zombie.Lua.LuaManager;
import zombie.characters.skills.PerkFactory;
import zombie.core.logger.ExceptionLogger;
import zombie.debug.DebugLog;
import zombie.debug.DebugOptions;
import zombie.scripting.ScriptManager;
import zombie.scripting.objects.Item;
import zombie.util.StringUtils;

public final class Translator {
    private static ArrayList<Language> availableLanguage = null;
    public static boolean debug = false;
    private static FileWriter debugFile = null;
    private static boolean debugErrors = false;
    private static final HashSet<String> debugItemEvolvedRecipeName = new HashSet();
    private static final HashSet<String> debugItem = new HashSet();
    private static final HashSet<String> debugMultiStageBuild = new HashSet();
    private static final HashSet<String> debugRecipe = new HashSet();
    private static final HashMap<String, String> moodles = new HashMap();
    private static final HashMap<String, String> ui = new HashMap();
    private static final HashMap<String, String> survivalGuide = new HashMap();
    private static final HashMap<String, String> contextMenu = new HashMap();
    private static final HashMap<String, String> farming = new HashMap();
    private static final HashMap<String, String> recipe = new HashMap();
    private static final HashMap<String, String> igui = new HashMap();
    private static final HashMap<String, String> sandbox = new HashMap();
    private static final HashMap<String, String> tooltip = new HashMap();
    private static final HashMap<String, String> challenge = new HashMap();
    private static final HashSet<String> missing = new HashSet();
    private static ArrayList<String> azertyLanguages = null;
    private static final HashMap<String, String> news = new HashMap();
    private static final HashMap<String, String> stash = new HashMap();
    private static final HashMap<String, String> multiStageBuild = new HashMap();
    private static final HashMap<String, String> moveables = new HashMap();
    private static final HashMap<String, String> makeup = new HashMap();
    private static final HashMap<String, String> gameSound = new HashMap();
    private static final HashMap<String, String> dynamicRadio = new HashMap();
    private static final HashMap<String, String> items = new HashMap();
    private static final HashMap<String, String> itemName = new HashMap();
    private static final HashMap<String, String> itemEvolvedRecipeName = new HashMap();
    private static final HashMap<String, String> recordedMedia = new HashMap();
    private static final HashMap<String, String> recordedMedia_EN = new HashMap();
    public static Language language = null;
    private static final String newsHeader = "<IMAGE:media/ui/dot.png> <SIZE:small> ";

    public static void loadFiles() {
        language = null;
        availableLanguage = null;
        File file = new File(zombie.ZomboidFileSystem.instance.getCacheDir() + File.separator + "translationProblems.txt");
        if (debug) {
            try {
                if (debugFile != null) {
                    debugFile.close();
                }

                debugFile = new FileWriter(file);
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
        }

        moodles.clear();
        ui.clear();
        survivalGuide.clear();
        items.clear();
        itemName.clear();
        contextMenu.clear();
        farming.clear();
        recipe.clear();
        igui.clear();
        sandbox.clear();
        tooltip.clear();
        challenge.clear();
        news.clear();
        missing.clear();
        stash.clear();
        multiStageBuild.clear();
        moveables.clear();
        makeup.clear();
        gameSound.clear();
        dynamicRadio.clear();
        itemEvolvedRecipeName.clear();
        recordedMedia.clear();
        DebugLog.log("translator: language is " + getLanguage());
        debugErrors = false;
        fillMapFromFile("Tooltip", tooltip);
        fillMapFromFile("IG_UI", igui);
        fillMapFromFile("Recipes", recipe);
        fillMapFromFile("Farming", farming);
        fillMapFromFile("ContextMenu", contextMenu);
        fillMapFromFile("SurvivalGuide", survivalGuide);
        fillMapFromFile("UI", ui);
        fillMapFromFile("Items", items);
        fillMapFromFile("ItemName", itemName);
        fillMapFromFile("Moodles", moodles);
        fillMapFromFile("Sandbox", sandbox);
        fillMapFromFile("Challenge", challenge);
        fillMapFromFile("Stash", stash);
        fillMapFromFile("MultiStageBuild", multiStageBuild);
        fillMapFromFile("Moveables", moveables);
        fillMapFromFile("MakeUp", makeup);
        fillMapFromFile("GameSound", gameSound);
        fillMapFromFile("DynamicRadio", dynamicRadio);
        fillMapFromFile("EvolvedRecipeName", itemEvolvedRecipeName);
        fillMapFromFile("Recorded_Media", recordedMedia);
        fillNewsFromFile(news);
        if (debug) {
            if (debugErrors) {
                DebugLog.log("translator: errors detected, please see " + file.getAbsolutePath());
            }

            debugItemEvolvedRecipeName.clear();
            debugItem.clear();
            debugMultiStageBuild.clear();
            debugRecipe.clear();
        }

        PerkFactory.initTranslations();
    }

    private static void fillNewsFromFile(HashMap<String, String> hashMap1) {
        HashMap hashMap0 = new HashMap();
        ArrayList arrayList = zombie.ZomboidFileSystem.instance.getModIDs();

        for (int _int = 0; _int < arrayList.size(); _int++) {
            String string = zombie.ZomboidFileSystem.instance.getModDir((String)arrayList.get(_int));
            if (string != null) {
                tryFillNewsFromFile(string, hashMap1, hashMap0, getLanguage());
                if (getLanguage() != getDefaultLanguage()) {
                    tryFillNewsFromFile(string, hashMap1, hashMap0, getDefaultLanguage());
                }
            }
        }

        tryFillNewsFromFile(".", hashMap1, hashMap0, getLanguage());
        if (getLanguage() != getDefaultLanguage()) {
            tryFillNewsFromFile(".", hashMap1, hashMap0, getDefaultLanguage());
        }

        for (Translator.News newsx : hashMap0.values()) {
            hashMap1.put("News_" + newsx.version + "_Disclaimer", newsx.toRichText());
        }

        hashMap0.clear();
    }

    private static void tryFillNewsFromFile(String string, HashMap<String, String> var1, HashMap<String, Translator.News> hashMap, Language languagex) {
        File file = new File(
            string
                + File.separator
                + "media"
                + File.separator
                + "lua"
                + File.separator
                + "shared"
                + File.separator
                + "Translate"
                + File.separator
                + languagex
                + File.separator
                + "News_"
                + languagex
                + ".txt"
        );
        if (file.exists()) {
            doNews(file, hashMap, languagex);
        }
    }

    private static void doNews(File file, HashMap<String, Translator.News> hashMap, Language languagex) {
        try {
            FileInputStream fileInputStream = new FileInputStream(file);

            try {
                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, Charset.forName(languagex.charset()));

                try {
                    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

                    try {
                        Translator.News newsx = null;
                        ArrayList arrayList = null;

                        String string0;
                        while ((string0 = bufferedReader.readLine()) != null) {
                            if (!string0.trim().isEmpty()) {
                                if (string0.startsWith("[VERSION]")) {
                                    String string1 = string0.replaceFirst("\\[VERSION\\]", "").trim();
                                    if (hashMap.containsKey(string1)) {
                                        newsx = null;
                                        arrayList = null;
                                    } else {
                                        hashMap.put(string1, newsx = new Translator.News(string1));
                                        arrayList = null;
                                    }
                                }

                                if (newsx != null) {
                                    if (string0.startsWith("[SECTION]")) {
                                        String string2 = string0.replaceFirst("\\[SECTION\\]", "").trim();
                                        arrayList = newsx.getOrCreateSectionList(string2);
                                    } else if (string0.startsWith("[NEWS]")) {
                                        arrayList = newsx.getOrCreateSectionList("[New]");
                                    } else if (string0.startsWith("[BALANCE]")) {
                                        arrayList = newsx.getOrCreateSectionList("[Balance]");
                                    } else if (string0.startsWith("[BUG FIX]")) {
                                        arrayList = newsx.getOrCreateSectionList("[Bug Fix]");
                                    } else if (arrayList != null) {
                                        addNewsLine(string0, arrayList);
                                    }
                                }
                            }
                        }
                    } catch (Throwable throwable0) {
                        try {
                            bufferedReader.close();
                        } catch (Throwable throwable1) {
                            throwable0.addSuppressed(throwable1);
                        }

                        throw throwable0;
                    }

                    bufferedReader.close();
                } catch (Throwable throwable2) {
                    try {
                        inputStreamReader.close();
                    } catch (Throwable throwable3) {
                        throwable2.addSuppressed(throwable3);
                    }

                    throw throwable2;
                }

                inputStreamReader.close();
            } catch (Throwable throwable4) {
                try {
                    fileInputStream.close();
                } catch (Throwable throwable5) {
                    throwable4.addSuppressed(throwable5);
                }

                throw throwable4;
            }

            fileInputStream.close();
        } catch (Exception exception) {
            ExceptionLogger.logException(exception);
        }
    }

    private static void addNewsLine(String string, ArrayList<String> arrayList) {
        if (string.startsWith("[BOLD]")) {
            string = string.replaceFirst("\\[BOLD\\]", "<IMAGE:media/ui/dot.png> <SIZE:medium>");
            arrayList.add(string + " <LINE> ");
        } else if (string.startsWith("[DOT2]")) {
            string = string.replaceFirst("\\[DOT2\\]", "<IMAGE:media/ui/dot2.png> <SIZE:small>");
            arrayList.add(string + " <LINE> ");
        } else if (string.startsWith("[NODOT]")) {
            string = string.replaceFirst("\\[NODOT\\]", " <SIZE:small> ");
            string = string + " <LINE> ";
            arrayList.add(string);
        } else {
            byte _byte = 7;
            arrayList.add("<IMAGE:media/ui/dot.png> <SIZE:small> " + " <INDENT:%d> ".formatted(21 - _byte) + string + " <INDENT:0> <LINE> ");
        }
    }

    public static ArrayList<String> getNewsVersions() {
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(news.keySet());

        for (int _int = 0; _int < arrayList.size(); _int++) {
            String string = (String)arrayList.get(_int);
            string = string.replace("News_", "");
            string = string.replace("_Disclaimer", "");
            arrayList.set(_int, string);
        }

        Collections.sort(arrayList);
        return arrayList;
    }

    private static void tryFillMapFromFile(String string1, String string0, HashMap<String, String> hashMap, Language languagex) {
        File file = new File(
            string1
                + File.separator
                + "media"
                + File.separator
                + "lua"
                + File.separator
                + "shared"
                + File.separator
                + "Translate"
                + File.separator
                + languagex
                + File.separator
                + string0
                + "_"
                + languagex
                + ".txt"
        );
        if (file.exists()) {
            parseFile(file, hashMap, languagex);
        }
    }

    private static void tryFillMapFromMods(String string1, HashMap<String, String> hashMap, Language languagex) {
        ArrayList arrayList = zombie.ZomboidFileSystem.instance.getModIDs();

        for (int _int = arrayList.size() - 1; _int >= 0; _int--) {
            String string0 = zombie.ZomboidFileSystem.instance.getModDir((String)arrayList.get(_int));
            if (string0 != null) {
                tryFillMapFromFile(string0, string1, hashMap, languagex);
            }
        }
    }

    public static void addLanguageToList(Language _language, ArrayList<Language> languages) {
        if (_language != null) {
            if (!languages.contains(_language)) {
                languages.add(_language);
                if (_language.base() != null) {
                    _language = Languages.instance.getByName(_language.base());
                    addLanguageToList(_language, languages);
                }
            }
        }
    }

    private static void fillMapFromFile(String string, HashMap<String, String> hashMap) {
        ArrayList arrayList = new ArrayList();
        addLanguageToList(getLanguage(), arrayList);
        addLanguageToList(getDefaultLanguage(), arrayList);

        for (int _int = 0; _int < arrayList.size(); _int++) {
            Language languagex = (Language)arrayList.get(_int);
            tryFillMapFromMods(string, hashMap, languagex);
            tryFillMapFromFile(zombie.ZomboidFileSystem.instance.base.getPath(), string, hashMap, languagex);
        }

        arrayList.clear();
    }

    private static void parseFile(File file, HashMap<String, String> hashMap, Language languagex) {
        String string0 = null;

        try {
            FileInputStream fileInputStream = new FileInputStream(file);

            try {
                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, Charset.forName(languagex.charset()));

                try {
                    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

                    try {
                        bufferedReader.readLine();
                        boolean _boolean = false;
                        String string1 = "";
                        String string2 = "";
                        int int0 = 1;
                        String string3 = file.getName().replace("_" + getDefaultLanguage(), "_" + getLanguage());

                        while ((string0 = bufferedReader.readLine()) != null) {
                            int0++;

                            try {
                                if (string0.contains("=") && string0.contains("\"")) {
                                    if (string0.trim().startsWith("Recipe_")) {
                                        string1 = string0.split("=")[0].replaceAll("Recipe_", "").replaceAll("_", " ").trim();
                                        string2 = string0.split("=")[1];
                                        string2 = string2.substring(string2.indexOf("\"") + 1, string2.lastIndexOf("\""));
                                    } else if (string0.trim().startsWith("DisplayName")) {
                                        String[] string4 = string0.split("=");
                                        if (string0.trim().startsWith("DisplayName_")) {
                                            string1 = string4[0].replaceAll("DisplayName_", "").trim();
                                        } else {
                                            string1 = string4[0].replaceAll("DisplayName", "").trim();
                                        }

                                        if ("Anti_depressants".equals(string1)) {
                                            string1 = "Antidepressants";
                                        }

                                        string2 = string4[1];
                                        string2 = string2.substring(string2.indexOf("\"") + 1, string2.lastIndexOf("\""));
                                    } else if (string0.trim().startsWith("EvolvedRecipeName_")) {
                                        String[] string5 = string0.split("=");
                                        string1 = string5[0].replaceAll("EvolvedRecipeName_", "").trim();
                                        string2 = string5[1];
                                        int int1 = string2.indexOf("\"");
                                        int int2 = string2.lastIndexOf("\"");
                                        string2 = string2.substring(int1 + 1, int2);
                                    } else if (string0.trim().startsWith("ItemName_")) {
                                        String[] string6 = string0.split("=");
                                        string1 = string6[0].replaceAll("ItemName_", "").trim();
                                        string2 = string6[1];
                                        int int3 = string2.indexOf("\"");
                                        int int4 = string2.lastIndexOf("\"");
                                        string2 = string2.substring(int3 + 1, int4);
                                    } else {
                                        string1 = string0.split("=")[0].trim();
                                        string2 = string0.substring(string0.indexOf("=") + 1);
                                        string2 = string2.substring(string2.indexOf("\"") + 1, string2.lastIndexOf("\""));
                                        if (string0.contains("..")) {
                                            _boolean = true;
                                        }
                                    }
                                } else if (string0.contains("--") || string0.trim().isEmpty() || !string0.trim().endsWith("..") && !_boolean) {
                                    _boolean = false;
                                } else {
                                    _boolean = true;
                                    string2 = string2 + string0.substring(string0.indexOf("\"") + 1, string0.lastIndexOf("\""));
                                }

                                if (!_boolean || !string0.trim().endsWith("..")) {
                                    if (!string1.isEmpty()) {
                                        if (!hashMap.containsKey(string1)) {
                                            hashMap.put(string1, string2);
                                            if (hashMap == recordedMedia && languagex == getDefaultLanguage()) {
                                                recordedMedia_EN.put(string1, string2);
                                            }

                                            if (debug && languagex == getDefaultLanguage() && getLanguage() != getDefaultLanguage()) {
                                                if (string3 != null) {
                                                    debugwrite(string3 + "\r\n");
                                                    string3 = null;
                                                }

                                                debugwrite("\t" + string1 + " = \"" + string2 + "\",\r\n");
                                                debugErrors = true;
                                            }
                                        } else if (debug && languagex == getDefaultLanguage() && getLanguage() != getDefaultLanguage()) {
                                            String string7 = (String)hashMap.get(string1);
                                            if (countSubstitutions(string7) != countSubstitutions(string2)) {
                                                debugwrite(
                                                    "wrong number of % substitutions in "
                                                        + string1
                                                        + "    "
                                                        + getDefaultLanguage()
                                                        + "=\""
                                                        + string2
                                                        + "\"    "
                                                        + getLanguage()
                                                        + "=\""
                                                        + string7
                                                        + "\"\r\n"
                                                );
                                                debugErrors = true;
                                            }
                                        }
                                    }

                                    _boolean = false;
                                    string2 = "";
                                    string1 = "";
                                }
                            } catch (Exception exception0) {
                                if (debug) {
                                    if (string3 != null) {
                                        debugwrite(string3 + "\r\n");
                                        string3 = null;
                                    }

                                    debugwrite("line " + int0 + ": " + string1 + " = " + string2 + "\r\n");
                                    if (debugFile != null) {
                                        exception0.printStackTrace(new PrintWriter(debugFile));
                                    }

                                    debugwrite("\r\n");
                                    debugErrors = true;
                                }
                            }
                        }
                    } catch (Throwable throwable0) {
                        try {
                            bufferedReader.close();
                        } catch (Throwable throwable1) {
                            throwable0.addSuppressed(throwable1);
                        }

                        throw throwable0;
                    }

                    bufferedReader.close();
                } catch (Throwable throwable2) {
                    try {
                        inputStreamReader.close();
                    } catch (Throwable throwable3) {
                        throwable2.addSuppressed(throwable3);
                    }

                    throw throwable2;
                }

                inputStreamReader.close();
            } catch (Throwable throwable4) {
                try {
                    fileInputStream.close();
                } catch (Throwable throwable5) {
                    throwable4.addSuppressed(throwable5);
                }

                throw throwable4;
            }

            fileInputStream.close();
        } catch (Exception exception1) {
            exception1.printStackTrace();
        }
    }

    public static String getText(String desc) {
        return getTextInternal(desc, false);
    }

    public static String getTextOrNull(String desc) {
        return getTextInternal(desc, true);
    }

    private static String getTextInternal(String string1, boolean _boolean) {
        if (ui == null) {
            loadFiles();
        }

        String string0 = null;
        if (string1.startsWith("UI_")) {
            string0 = (String)ui.get(string1);
        } else if (string1.startsWith("Moodles_")) {
            string0 = (String)moodles.get(string1);
        } else if (string1.startsWith("SurvivalGuide_")) {
            string0 = (String)survivalGuide.get(string1);
        } else if (string1.startsWith("Farming_")) {
            string0 = (String)farming.get(string1);
        } else if (string1.startsWith("IGUI_")) {
            string0 = (String)igui.get(string1);
        } else if (string1.startsWith("ContextMenu_")) {
            string0 = (String)contextMenu.get(string1);
        } else if (string1.startsWith("GameSound_")) {
            string0 = (String)gameSound.get(string1);
        } else if (string1.startsWith("Sandbox_")) {
            string0 = (String)sandbox.get(string1);
        } else if (string1.startsWith("Tooltip_")) {
            string0 = (String)tooltip.get(string1);
        } else if (string1.startsWith("Challenge_")) {
            string0 = (String)challenge.get(string1);
        } else if (string1.startsWith("MakeUp")) {
            string0 = (String)makeup.get(string1);
        } else if (string1.startsWith("News_")) {
            string0 = (String)news.get(string1);
        } else if (string1.startsWith("Stash_")) {
            string0 = (String)stash.get(string1);
        } else if (string1.startsWith("RM_")) {
            string0 = (String)recordedMedia.get(string1);
        }

        String string2 = Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "*" : null;
        if (string0 == null) {
            if (_boolean) {
                return null;
            }

            if (!missing.contains(string1)) {
                if (Core.bDebug) {
                    DebugLog.log("ERROR: Missing translation \"" + string1 + "\"");
                }

                if (debug) {
                    debugwrite("ERROR: Missing translation \"" + string1 + "\"\r\n");
                }

                missing.add(string1);
            }

            string0 = string1;
            string2 = Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "!" : null;
        }

        if (string0.contains("<br>")) {
            return string0.replaceAll("<br>", "\n");
        } else {
            return string2 == null ? string0 : string2 + string0;
        }
    }

    private static int countSubstitutions(String string) {
        int _int = 0;
        if (string.contains("%1")) {
            _int++;
        }

        if (string.contains("%2")) {
            _int++;
        }

        if (string.contains("%3")) {
            _int++;
        }

        if (string.contains("%4")) {
            _int++;
        }

        return _int;
    }

    private static String subst(String string0, String string1, Object object) {
        if (object != null) {
            if (object instanceof Double) {
                double _double = (Double)object;
                string0 = string0.replaceAll(string1, _double == (double)((long)_double) ? Long.toString((long)_double) : object.toString());
            } else {
                string0 = string0.replaceAll(string1, Matcher.quoteReplacement(object.toString()));
            }
        }

        return string0;
    }

    public static String getText(String desc, Object arg1) {
        String string = getText(desc);
        return subst(string, "%1", arg1);
    }

    public static String getText(String desc, Object arg1, Object arg2) {
        String string = getText(desc);
        string = subst(string, "%1", arg1);
        return subst(string, "%2", arg2);
    }

    public static String getText(String desc, Object arg1, Object arg2, Object arg3) {
        String string = getText(desc);
        string = subst(string, "%1", arg1);
        string = subst(string, "%2", arg2);
        return subst(string, "%3", arg3);
    }

    public static String getText(String desc, Object arg1, Object arg2, Object arg3, Object arg4) {
        String string = getText(desc);
        string = subst(string, "%1", arg1);
        string = subst(string, "%2", arg2);
        string = subst(string, "%3", arg3);
        return subst(string, "%4", arg4);
    }

    public static String getTextOrNull(String desc, Object arg1) {
        String string = getTextOrNull(desc);
        return string == null ? null : subst(string, "%1", arg1);
    }

    public static String getTextOrNull(String desc, Object arg1, Object arg2) {
        String string = getTextOrNull(desc);
        if (string == null) {
            return null;
        } else {
            string = subst(string, "%1", arg1);
            return subst(string, "%2", arg2);
        }
    }

    public static String getTextOrNull(String desc, Object arg1, Object arg2, Object arg3) {
        String string = getTextOrNull(desc);
        if (string == null) {
            return null;
        } else {
            string = subst(string, "%1", arg1);
            string = subst(string, "%2", arg2);
            return subst(string, "%3", arg3);
        }
    }

    public static String getTextOrNull(String desc, Object arg1, Object arg2, Object arg3, Object arg4) {
        String string = getTextOrNull(desc);
        if (string == null) {
            return null;
        } else {
            string = subst(string, "%1", arg1);
            string = subst(string, "%2", arg2);
            string = subst(string, "%3", arg3);
            return subst(string, "%4", arg4);
        }
    }

    private static String getDefaultText(String string) {
        return changeSomeStuff((String)((KahluaTable)LuaManager.env.rawget(string.split("_")[0] + "_" + getDefaultLanguage().name())).rawget(string));
    }

    private static String changeSomeStuff(String string) {
        return string;
    }

    public static void setLanguage(Language newlanguage) {
        if (newlanguage == null) {
            newlanguage = getDefaultLanguage();
        }

        language = newlanguage;
    }

    public static void setLanguage(int languageId) {
        Language languagex = Languages.instance.getByIndex(languageId);
        setLanguage(languagex);
    }

    public static Language getLanguage() {
        if (language == null) {
            String string = Core.getInstance().getOptionLanguageName();
            if (!StringUtils.isNullOrWhitespace(string)) {
                language = Languages.instance.getByName(string);
            }
        }

        if (language == null) {
            language = Languages.instance.getByName(System.getProperty("user.language").toUpperCase());
        }

        if (language == null) {
            language = getDefaultLanguage();
        }

        return language;
    }

    public static String getCharset() {
        return getLanguage().charset();
    }

    public static ArrayList<Language> getAvailableLanguage() {
        if (availableLanguage == null) {
            availableLanguage = new ArrayList();

            for (int _int = 0; _int < Languages.instance.getNumLanguages(); _int++) {
                availableLanguage.add(Languages.instance.getByIndex(_int));
            }
        }

        return availableLanguage;
    }

    public static String getDisplayItemName(String trim) {
        Object object = null;
        object = (String)items.get(trim.replaceAll(" ", "_").replaceAll("-", "_"));
        return (String)(object == null ? trim : object);
    }

    public static String getItemNameFromFullType(String fullType) {
        if (!fullType.contains(".")) {
            throw new IllegalArgumentException("fullType must contain \".\" i.e. module.type");
        } else {
            String string = (String)itemName.get(fullType);
            if (string == null) {
                if (debug && getLanguage() != getDefaultLanguage() && !debugItem.contains(fullType)) {
                    debugItem.add(fullType);
                }

                Item item = ScriptManager.instance.getItem(fullType);
                if (item == null) {
                    string = fullType;
                } else {
                    string = item.getDisplayName();
                }

                itemName.put(fullType, string);
            }

            return string;
        }
    }

    public static void setDefaultItemEvolvedRecipeName(String fullType, String english) {
        if (getLanguage() == getDefaultLanguage()) {
            if (!fullType.contains(".")) {
                throw new IllegalArgumentException("fullType must contain \".\" i.e. module.type");
            } else if (!itemEvolvedRecipeName.containsKey(fullType)) {
                itemEvolvedRecipeName.put(fullType, english);
            }
        }
    }

    public static String getItemEvolvedRecipeName(String fullType) {
        if (!fullType.contains(".")) {
            throw new IllegalArgumentException("fullType must contain \".\" i.e. module.type");
        } else {
            String string = (String)itemEvolvedRecipeName.get(fullType);
            if (string == null) {
                if (debug && getLanguage() != getDefaultLanguage() && !debugItemEvolvedRecipeName.contains(fullType)) {
                    debugItemEvolvedRecipeName.add(fullType);
                }

                Item item = ScriptManager.instance.getItem(fullType);
                if (item == null) {
                    string = fullType;
                } else {
                    string = item.getDisplayName();
                }

                itemEvolvedRecipeName.put(fullType, string);
            }

            return string;
        }
    }

    public static String getMoveableDisplayName(String name) {
        String string0 = name.replaceAll(" ", "_").replaceAll("-", "_").replaceAll("'", "").replaceAll("\\.", "");
        String string1 = (String)moveables.get(string0);
        if (string1 == null) {
            return Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "!" + name : name;
        } else {
            return Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "*" + string1 : string1;
        }
    }

    public static String getMoveableDisplayNameOrNull(String name) {
        String string0 = name.replaceAll(" ", "_").replaceAll("-", "_").replaceAll("'", "").replaceAll("\\.", "");
        String string1 = (String)moveables.get(string0);
        if (string1 == null) {
            return null;
        } else {
            return Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "*" + string1 : string1;
        }
    }

    public static String getMultiStageBuild(String name) {
        String string = (String)multiStageBuild.get("MultiStageBuild_" + name);
        if (string == null) {
            if (debug && getLanguage() != getDefaultLanguage() && !debugMultiStageBuild.contains(name)) {
                debugMultiStageBuild.add(name);
            }

            return name;
        } else {
            return string;
        }
    }

    public static String getRecipeName(String name) {
        String string = null;
        string = (String)recipe.get(name);
        if (string != null && !string.isEmpty()) {
            return string;
        } else {
            if (debug && getLanguage() != getDefaultLanguage() && !debugRecipe.contains(name)) {
                debugRecipe.add(name);
            }

            return name;
        }
    }

    public static Language getDefaultLanguage() {
        return Languages.instance.getDefaultLanguage();
    }

    public static void debugItemEvolvedRecipeNames() {
        if (debug && !debugItemEvolvedRecipeName.isEmpty()) {
            debugwrite("EvolvedRecipeName_" + getLanguage() + ".txt\r\n");
            ArrayList arrayList = new ArrayList();
            arrayList.addAll(debugItemEvolvedRecipeName);
            Collections.sort(arrayList);

            for (String string : arrayList) {
                debugwrite("\tEvolvedRecipeName_" + string + " = \"" + (String)itemEvolvedRecipeName.get(string) + "\",\r\n");
            }

            debugItemEvolvedRecipeName.clear();
        }
    }

    public static void debugItemNames() {
        if (debug && !debugItem.isEmpty()) {
            debugwrite("ItemName_" + getLanguage() + ".txt\r\n");
            ArrayList arrayList = new ArrayList();
            arrayList.addAll(debugItem);
            Collections.sort(arrayList);

            for (String string : arrayList) {
                debugwrite("\tItemName_" + string + " = \"" + (String)itemName.get(string) + "\",\r\n");
            }

            debugItem.clear();
        }
    }

    public static void debugMultiStageBuildNames() {
        if (debug && !debugMultiStageBuild.isEmpty()) {
            debugwrite("MultiStageBuild_" + getLanguage() + ".txt\r\n");
            ArrayList arrayList = new ArrayList();
            arrayList.addAll(debugMultiStageBuild);
            Collections.sort(arrayList);

            for (String string : arrayList) {
                debugwrite("\tMultiStageBuild_" + string + " = \"\",\r\n");
            }

            debugMultiStageBuild.clear();
        }
    }

    public static void debugRecipeNames() {
        if (debug && !debugRecipe.isEmpty()) {
            debugwrite("Recipes_" + getLanguage() + ".txt\r\n");
            ArrayList arrayList = new ArrayList();
            arrayList.addAll(debugRecipe);
            Collections.sort(arrayList);

            for (String string : arrayList) {
                debugwrite("\tRecipe_" + string.replace(" ", "_") + " = \"\",\r\n");
            }

            debugRecipe.clear();
        }
    }

    private static void debugwrite(String string) {
        if (debugFile != null) {
            try {
                debugFile.write(string);
                debugFile.flush();
            } catch (IOException iOException) {
            }
        }
    }

    public static ArrayList<String> getAzertyMap() {
        if (azertyLanguages == null) {
            azertyLanguages = new ArrayList();
            azertyLanguages.add("FR");
        }

        return azertyLanguages;
    }

    public static String getRadioText(String s) {
        String string = (String)dynamicRadio.get(s);
        return string == null ? s : string;
    }

    public static String getTextMediaEN(String desc) {
        if (ui == null) {
            loadFiles();
        }

        String string0 = null;
        if (desc.startsWith("RM_")) {
            string0 = (String)recordedMedia_EN.get(desc);
        }

        String string1 = Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "*" : null;
        if (string0 == null) {
            if (!missing.contains(desc) && Core.bDebug) {
                if (Core.bDebug) {
                    DebugLog.log("ERROR: Missing translation \"" + desc + "\"");
                }

                if (debug) {
                    debugwrite("ERROR: Missing translation \"" + desc + "\"\r\n");
                }

                missing.add(desc);
            }

            string0 = desc;
            string1 = Core.bDebug && DebugOptions.instance.TranslationPrefix.getValue() ? "!" : null;
        }

        if (string0.contains("<br>")) {
            return string0.replaceAll("<br>", "\n");
        } else {
            return string1 == null ? string0 : string1 + string0;
        }
    }

    private static final class News {
        String version;
        final ArrayList<String> sectionNames = new ArrayList();
        final HashMap<String, ArrayList<String>> sectionLists = new HashMap();

        News(String string) {
            this.version = string;
        }

        ArrayList<String> getOrCreateSectionList(String string) {
            if (this.sectionNames.contains(string)) {
                return (ArrayList<String>)this.sectionLists.get(string);
            } else {
                this.sectionNames.add(string);
                ArrayList arrayList = new ArrayList();
                this.sectionLists.put(string, arrayList);
                return arrayList;
            }
        }

        String toRichText() {
            StringBuilder stringBuilder = new StringBuilder("");

            for (String string0 : this.sectionNames) {
                ArrayList arrayList = (ArrayList)this.sectionLists.get(string0);
                if (!arrayList.isEmpty()) {
                    stringBuilder.append("<LINE> <LEFT> <SIZE:medium> %s <LINE> <LINE> ".formatted(string0));

                    for (String string1 : arrayList) {
                        stringBuilder.append(string1);
                    }
                }
            }

            return stringBuilder.toString();
        }
    }
}
